package com.lmaos.basetools.files;

import java.io.File;
import java.util.concurrent.Executor;

public class FileMgImpl implements FileMg{
	// 线程池
	Executor exec = null;
	
	public FileMgImpl() {
	}
	/**
	 * 
	 * @param exec 线程池
	 */
	public FileMgImpl(Executor exec) {
		this.exec = exec;
	}

	@Override
	public void addFileListener(FileListener fileListener, String path,long sleep, String... suffixs) {
		File superPath = new File(path);
		if(superPath.exists()&&superPath.isDirectory()){
			FileListenerThread fileListenerThread = 
			new FileListenerThread(superPath, fileListener, sleep, exec, suffixs);
			Thread t = new Thread(fileListenerThread);
			t.start();
		}else{
			
		}
	}

	
	public static void main(String[] args) {
		FileMgImpl f = new FileMgImpl();
		f.addFileListener(new FileListener() {
			
			@Override
			public void fileOnLoad(File file) {
				System.out.println("fileOnLoad-"+file);
				
			}
			
			@Override
			public void fileDelete(File file) {
				System.out.println("fileDelete-"+file);
				
			}
			
			@Override
			public void fileCreate(File file) {
				System.out.println("fileCreate-"+file);
				
			}
			
			@Override
			public void fileChange(File file) {
				System.out.println("fileChange-"+file);
				
			}
			
			@Override
			public void directoryOnLoad(File file) {
				System.out.println("directoryOnLoad-"+file);
				
			}
			
			@Override
			public void directoryDelete(File file) {
				System.out.println("directoryDelete-"+file);
				
			}
			
			@Override
			public void directoryCreate(File file) {
				System.out.println("directoryCreate-"+file);
				
			}
			
			@Override
			public void directoryChange(File file) {
				System.out.println("directoryChange-"+file);
				System.out.println(file.lastModified());
				
			}
		}, "/Users/zhangxingyu/project/ex/", 3000, ".html");
	}
}
